﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using IceUtilInternal;
using DSServer.Misc;
using DSServer.Banking;
using DSServer.Communication;

namespace DSServer.Banking
{
    class BankingEvictor : EvictorBase
    {
        private readonly string LoginOperation = "login";

     
        protected override Ice.Object add(Ice.Current c, out object cookie)
        {   
                                                    //ice_ internal ice call
            if (c.operation != LoginOperation && !c.operation.StartsWith("ice_"))
                throw new UserNotLoggedException();
            cookie = null;
            return new AccountI();
        }

        protected override void evict(Ice.Object servant, object cookie)
        {
            AccountI account = (AccountI)servant;
            try
            {
                account.InternalLogout();
            }
            catch(UserNotLoggedException)
            {
                //pass
            }
        }
    }
}
